const DefaultStore = {
    loading:true,
    categoryload:true,
    productload:true,
    categoryadding:false,
    productadding:false,
    categorylist:[],
    pruductlist:[],
    productCategorys:[],
    categoryIndex:0,
    categoryPicker:[],
    categoryValue:[],
    showCategory:{
        category_id:0,
        image:"",
        name:"",
        name2:"",
        description:"",
        sort_order:"1",
        status:1,
        version:1,
        path:""
    },
    showProduct:{
        product_id:"",
        qty:0,
        price:"0",
        special_price:"0",
        points:"0",
        name:"",
        name2:"",
        description:"",
        sort_order:0,
        status:1,
        categories:"",
        images:[],
        options:[],
        path:null,
        version:1
    },
    productOptions:{
        option_id:"",
        name:"",
        required:true,
        sort_order:1,
        values:[]
    },
    productOption:{
        option_id:0,
        name:"",
        default:"",
        required:true,
        sort_order:"0",
        values:[]
    },
    productOptionValue:{
        value_id:"",
        name:"",
        sort_order:0,
        price_prefix:"+",
        price:0,
        points_prefix:"+",
        points:0
    }
    
}
export const TYPES = {
    GETCATEGORYLIST:"menu/getcategorylist",
    CHANGECATEGORYLOADING:"menu/changecategoryloading",
    CHANGECATEGORYADDING:"menu/changecategoryadding",
    SETCATEGORYINFO:"menu/setcategoryinfo",
    SETSHOWCATEGORY:"menu/setshowcategory",
    INITSHOWCATEGORY:"menu/initshowcategory",
    SETPRODUCTLIST:"menu/setproductlist",
    CHANGEPRODUCTLOADING:"menu/changeproductloading",
    CHANGECATEGORYINDEX:"menu/changecategoryindex",
    CHANGELOADING:"menu/changeloading",
    SETSHOWPRODUCT:"menu/changeproduct",
    SETPRODUCTOPTIONINFO:"menu/setproductoptioninfo",
    SETDEFAULTPRODUCTINFO:"menu/setdefaultproductinfo",
    SETPRODEUCTOPTION:"menu/setproductoption",
    SETPRODUCTOPTIONVALUE:"menu/setproductoptionvalue",
    SETDETAULTOPTION:"menu/setdefaultoption",
    SETDETAULTOPTIONVALUE:"menu/setdefaultoptionvalue",
    SETPRODUCTADDING:"menu.setproductadding"
}
export default  (store = DefaultStore, action) => {
    switch (action.type) {
        case TYPES.GETCATEGORYLIST:
            return {
                ...store,
                categorylist:action.categorylist,
                categoryload:false,
                loading:false,
                categoryadding:false,
                productadding:false
            }
        break;
        case TYPES.CHANGECATEGORYLOADING:
            return {
                ...store,
                categoryload:action.categoryload
            }
        break;
        case TYPES.SETCATEGORYINFO:
            return {
                ...store,
                showCategory:action.showCategory
            }
        break;
        case TYPES.CHANGECATEGORYADDING:
            return {
                ...store,
                categoryadding:action.categoryadding
            }
        break;
        case TYPES.SETSHOWCATEGORY:
            return {
                ...store,
                showCategory:action.showCategory
            }
        break;
        case TYPES.INITSHOWCATEGORY:
            return {
                ...store,
                showCategory:{
                    category_id:0,
                    image:"",
                    name:"",
                    name2:"",
                    description:"",
                    sort_order:"1",
                    status:1,
                    version:1,
                    path:""
                }
            }
        break;
        case TYPES.SETDEFAULTPRODUCTINFO:
            return {
                ...store,
                showProduct:{
                    product_id:"",
                    qty:0,
                    price:"",
                    special_price:"",
                    points:"",
                    name:"",
                    name2:"",
                    description:"",
                    sort_order:"0",
                    status:1,
                    categories:"",
                    images:[],
                    options:[],
                    path:null
                }
            }
        break;
        case TYPES.SETPRODUCTLIST:
            return {
                ...store,
                pruductlist:action.pruductlist,
                productload:false,
                productCategorys:action.categories,
                loading:false,
                categoryPicker:action.categoryPicker
            }
        break;
        case TYPES.CHANGEPRODUCTLOADING:
            return {
                ...store,
                productload:action.productload,
                loading:false
            }
        break;
        case TYPES.CHANGECATEGORYINDEX:
            return {
                ...store,
                categoryIndex:action.categoryIndex,
                pruductlist:action.pruductlist
            }
        break;
        case TYPES.CHANGELOADING:
            return {
                ...store,
                loading:action.loading
            }
        break;
        case TYPES.SETSHOWPRODUCT:
            return {
                ...store,
                showProduct:action.showProduct
            }
        break;
        case TYPES.SETPRODUCTOPTIONINFO:
            return {
                ...store,
                productOptions:action.productOptions
            }
        break;
        case TYPES.SETPRODEUCTOPTION:
            return {
                ...store,
                productOption:action.productOption
            }
        break;
        case TYPES.SETPRODUCTOPTIONVALUE:
            return {
                ...store,
                productOptionValue:action.productOptionValue
            }
        break;
        case TYPES.SETDETAULTOPTION:
            return {
                ...store,
                productOption:{
                    option_id:0,
                    name:"",
                    default:"",
                    required:true,
                    sort_order:"0",
                    values:[]
                }
            }
        break;
        case TYPES.SETDETAULTOPTIONVALUE:
            return {
                ...store,
                productOptionValue:{
                    value_id:"",
                    name:"",
                    sort_order:0,
                    price_prefix:"+",
                    price:0,
                    points_prefix:"+",
                    points:0
                }
            }
        break;
        case TYPES.SETPRODUCTADDING:
            return {
                ...store,
                productadding:action.productadding
            }
        break;
        default:
            return store;
            break;
    }
}